/*******************************************************************************
 * Copyright (c) 2006 CEA LIST.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA LIST - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.tabbedproperties.section;

import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.eclipse.uml2.uml.Port;

import com.cea.papyrus.core.editpart.IUMLElementEditPart;
import com.cea.papyrus.core.tabbedproperties.PropertyViewSection;
import com.cea.papyrus.tabbedproperties.composites.PortCharacteristicsSWTComposite;

/**
 * @author Sebastien Gerard
 * This class implements the support for specifying both following attributes of a UML Port:
 * -> isBehavior: Boolean = false : Specifies whether requests arriving at this port are 
 * sent to the classifier behavior of this classifier. Such ports are referred to as behavior port.
 * -> isService: Boolean = false : If true, indicates that this port is used to provide the 
 * published functionality of a classifier. If false, this port is used to implement the classifier 
 * but is not part of the essential externally-visible functionality of the classifier 
 * and can, therefore, be altered or deleted along with the internal implementation of the classifier
 *  and other properties that are considered part of its implementation.
 */
public class PortCharacteristicsSection extends PropertyViewSection {
	
	/**
	 * Declaration of a SWT composite dedicated to specify Port attributes: isBehavior and isService
	 */
	private PortCharacteristicsSWTComposite portCharacSWTComposite;
	
	/* (non-Javadoc)
	 * @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#createControls(org.eclipse.swt.widgets.Composite, org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage)
	 */
	/**
	 * {@inheritDoc} 
	 */
	@Override
	public void createControls(Composite parent,
            TabbedPropertySheetPage tabbedPropertySheetPage) {
		
        super.createControls(parent, tabbedPropertySheetPage);
        portCharacSWTComposite = new PortCharacteristicsSWTComposite();
        portCharacSWTComposite.createContent(parent, tabbedPropertySheetPage.getWidgetFactory());
        
 	}
	
	/**
	 * 
	 */
	@Override
	public void refresh() {
		portCharacSWTComposite.refresh();
	}
	
    /* (non-Javadoc)
     * @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#setInput(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
     */
    /**
     * 
     * {@inheritDoc}
     */
    @Override
	public void setInput(IWorkbenchPart part, ISelection selection) {
        super.setInput(part, selection);
    	Assert.isTrue(selection instanceof IStructuredSelection);
        Object input = ((IStructuredSelection) selection).getFirstElement();
        if(input instanceof IUMLElementEditPart) {
        	portCharacSWTComposite.setElement((Port) ((IUMLElementEditPart) input).getUmlElement());
		}
    }
    
    /*
     * (non-Javadoc)
     * @see com.cea.papyrus.core.ui.properties.tabbed.PropertyViewSection#dispose()
     */
    /**
     * {@inheritDoc}
     */
    public void dispose(){
    	super.dispose();
    	if(portCharacSWTComposite!=null)
    		portCharacSWTComposite.dispose();
    }
}

